package com.atguigu.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * 基于RestFul风格的请求方式
 */
@Controller
@RequestMapping("restFul")
public class RestFulController {
    /**
     * RestFul风格的GET请求
     * 浏览器的地址栏，会携带多个参数
     */
    @RequestMapping("restGetParams/{id}/{name}")
    public String restGetParams(@PathVariable("id") Integer id,@PathVariable("name") String name){
        System.out.println("RestFul==GET::"+id+"::"+name);
        return "index";
    }

    /**
     * RestFul风格的DELETE请求
     */
    @RequestMapping(value = "restDelete",method = RequestMethod.DELETE)
    public void restDelete(String name){
        System.out.println("RestFul==DELETE::"+name);
        //return "index";不能转发，DELETE请求，转发会页面会携带请求，浏览器不认识
    }

    /**
     * RestFul风格的PUT请求
     */
    @RequestMapping(value = "restPut",method = RequestMethod.PUT)
    public void restPut(String name){
        System.out.println("RestFul==PUT::"+name);
        //return "index";不能转发，PUT请求，转发会页面会携带请求，浏览器不认识
    }

    /**
     * ResultFul风格的post请求
     */
    @RequestMapping(value = "restPost",method = RequestMethod.POST)
    public String restPost(String name){
        System.out.println("RestFul==POST::"+name);
        return "index";
    }

    /**
     * ResultFul风格的get请求
     * @RequestMapping:注解属性： method 请求方式
     *
     * 注解： @PathVariable 含义是路径变量
     * 获取到URL地址中的变量
     * 注解只能添加在参数上面
     * @PathVariable("id")  id参数的占位符
     * 取出路径上的参数，并传递到方法的参数id上
     *
     *                                      value = "restGet/{id}" 请求地址上的的参数占位符
     * 浏览器的地址栏： http://localhost:8080/restFul/restGet/1.do
     */
    @RequestMapping(value = "restGet/{id}",method = RequestMethod.GET)
    public String restGet(@PathVariable("id") String id){
        System.out.println("RestFul==GET::"+id);
        return "index";
    }
}
